from django.http import HttpResponseRedirect, HttpResponse, Http404
from httplib import HTTPResponse
from django.contrib.auth.models import User
from django.conf.app_template import models
from django.contrib import auth
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required

def requires_login(view):
    def new_view(request, *args, **kwargs):
        if not request.user.is_authenticated():
            return HttpResponseRedirect('/accounts/login/')
        return view(request, *args, **kwargs)
    return new_view

@login_required(redirect_field_name='/accounts/login/')
def profile (request):
    user = request.user
    return render_to_response('registration/profile.html',locals())
    
#def login_view(request):
#    username = request.POST.get('username', '')
#    password = request.POST.get('password', '')
#    user = auth.authenticate(username=username, password=password)
#    if user is not None and user.is_active:
#        # Correct password, and the user is marked "active"
#        auth.login(request, user)
#        # Redirect to a success page.
#        return HttpResponseRedirect("/account/loggedin/")
#    else:
#        # Show an error page
#        return HttpResponseRedirect("/account/invalid/")
#    
#def logout_view(request):
#    auth.logout(request)
#    # Redirect to a success page.
#    return HttpResponseRedirect("/account/loggedout/")
